//
//  HomeCollectionCell.m
//  ChatForHot
//
//  Created by FLY on 2018/10/12.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "HomeCollectionCell.h"

@implementation HomeCollectionCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.contentView.layer.masksToBounds = YES;
        self.contentView.layer.cornerRadius = 8;
        self.contentView.layer.borderWidth = 0.5;
        self.contentView.layer.borderColor = HOTCHATHexColor(0xD1D1D1).CGColor;

        
        [self.contentView addSubview:self.HOTCHATimgView];
        [self.contentView addSubview:self.HOTCHATonlineImgView];
        [self.contentView addSubview:self.HOTCHATnameLab];
        [self.contentView addSubview:self.HOTCHATvipimgView];
        [self.contentView addSubview:self.HOTCHATdistancelab];
        [self.contentView addSubview:self.HOTCHATcertifyImgView];

        [self.HOTCHATimgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.left.top.right.equalTo(self.contentView);
            make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-33);
        }];
        [self.HOTCHATcertifyImgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.contentView.mas_left);
            make.top.equalTo(self.contentView.mas_top).mas_offset(14);
            
        }];
        [self.HOTCHATonlineImgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(self.HOTCHATimgView.mas_bottom).mas_offset(33/2);
            make.left.equalTo(self.contentView.mas_left).mas_offset(5);
        }];
        [self.HOTCHATnameLab mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(self.HOTCHATonlineImgView.mas_centerY);
            make.left.equalTo(self.HOTCHATonlineImgView.mas_right).mas_offset(5);
            make.right.lessThanOrEqualTo(self.contentView).offset(-76);
        }];
        [self.HOTCHATvipimgView mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(self.HOTCHATnameLab.mas_centerY);
            make.left.equalTo(self.HOTCHATnameLab.mas_right).mas_offset(2);
        }];
        [self.HOTCHATdistancelab mas_updateConstraints:^(MASConstraintMaker *make) {
            
            make.centerY.equalTo(self.HOTCHATvipimgView.mas_centerY);
            make.right.equalTo(self.contentView.mas_right).mas_offset(-5);
//            make.width.mas_equalTo(50);
        }];
        
        
        [self.HOTCHATnameLab setContentHuggingPriority:(UILayoutPriorityDefaultHigh) forAxis:(UILayoutConstraintAxisHorizontal)];
    }
    return self;
    
}
- (void)setModel:(UserInfoModel *)model{
    _model = model;
    if (model) {
        self.HOTCHATvipimgView.hidden = NO;
        NSString *imgStr = @"";
        if (model.isWrite.integerValue == 1) {
            
            imgStr = @"all_ic_writevip";
        }else if (model.isDiamonds.integerValue == 1) {
            
            imgStr = @"all_ic_diamondsvip";
        }else if (model.isExtreme.integerValue == 1) {
            
            imgStr = @"all_ic_vip";
        }else{
            
            self.HOTCHATvipimgView.hidden = YES;
        }
        [self.HOTCHATimgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIHEADER,model.headPic]] placeholderImage:[UIImage imageNamed:@"personal_atatar_but_h"]];
        
        self.HOTCHATvipimgView.image = [UIImage imageNamed:imgStr];
        
        self.HOTCHATnameLab.text = model.nickName.length >= 9 ? [NSString stringWithFormat:@"%@.",[model.nickName substringToIndex:8]] : model.nickName;
        
        self.HOTCHATdistancelab.text = model.distance.length >= 8 ? @"999+km" : model.distance;
        
        self.HOTCHATcertifyImgView.hidden = model.isApprove.integerValue != 1;
    }
}
//lazzy
- (UIImageView *)HOTCHATimgView{
    
    if (_HOTCHATimgView == nil) {
        
        _HOTCHATimgView = [[UIImageView alloc]init];
        _HOTCHATimgView.image = [UIImage imageNamed:@"personal_atatar_but_h"];
        _HOTCHATimgView.contentMode = UIViewContentModeScaleAspectFill;
        _HOTCHATimgView.clipsToBounds = YES;
    }
    return _HOTCHATimgView;
}
- (UIImageView *)HOTCHATcertifyImgView{
    
    if (_HOTCHATcertifyImgView == nil) {
        
        _HOTCHATcertifyImgView = [[UIImageView alloc]init];
        _HOTCHATcertifyImgView.image = [UIImage imageNamed:@"home_ic_certified"];
        _HOTCHATcertifyImgView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _HOTCHATcertifyImgView;
}
- (UIImageView *)HOTCHATonlineImgView{
    
    if (_HOTCHATonlineImgView == nil) {
        
        _HOTCHATonlineImgView = [[UIImageView alloc]init];
        _HOTCHATonlineImgView.image = [UIImage imageNamed:@"all_online"];
        _HOTCHATonlineImgView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _HOTCHATonlineImgView;
}
- (UILabel *)HOTCHATnameLab{
    
    if (_HOTCHATnameLab == nil) {
        
        _HOTCHATnameLab = [[UILabel alloc]init];
        _HOTCHATnameLab.textColor = HOTCHATHexColor(0x111111);
        _HOTCHATnameLab.font = [UIFont boldSystemFontOfSize:16];
    }
    return _HOTCHATnameLab;
}
- (UIImageView *)HOTCHATvipimgView{
    
    if (_HOTCHATvipimgView == nil) {
        
        _HOTCHATvipimgView = [[UIImageView alloc]init];
        _HOTCHATvipimgView.image = [UIImage imageNamed:@"all_ic_vip"];
        _HOTCHATvipimgView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _HOTCHATvipimgView;
}
- (UILabel *)HOTCHATdistancelab{
    
    if (_HOTCHATdistancelab == nil) {
        
        _HOTCHATdistancelab = [[UILabel alloc]init];
        _HOTCHATdistancelab.textColor = HOTCHATHexColor(0x9E9E9E);
        _HOTCHATdistancelab.font = [UIFont boldSystemFontOfSize:13];
        _HOTCHATdistancelab.textAlignment = NSTextAlignmentRight;
    }
    return _HOTCHATdistancelab;
}

@end
